#!/usr/bin/perl -w # useful for syntax highlighting
package clreqd_modules;

use strict;
use lvm;
use Data::Dumper;
use cldb;

sub ss_onode_postmigrate {
my %ARGS=@_;
my $application=$ARGS{APPLICATION};
my $new_node=$ARGS{NNODE};

	my $CLDB=new cldb("$::ENV{TRUECL_CFG}/config.db");
	if(!defined($CLDB)) {
		return "ERROR Unable to connect to 'config' database.";
	}
	my $res=$CLDB->get_rows("SELECT * FROM applications WHERE name = '$application';");
	if(!defined($res->[0]->{nodes})) {
		return "ERROR Application '$application' is unknown.";
	}

	$CLDB->disconnect; $CLDB=undef;
	my $s=$res->[0]->{storage};
	#################################################################
	# Now open open the configuration database to get the storage	#
	# spec and list of volume groups...				#
	#################################################################

	if(! -f "$::ENV{TRUECL_CODE}/lib/storage_spec/$s.pm") {
		return "ERROR - Storage spec '$s' not available.";
	}

	eval "use storage_spec::$s;";
	my $STORAGE=eval "new storage_spec::$s;";
	if(!defined($STORAGE)) {
		return "ERROR Unable to use storage spec - storage_spec::$s\nError: " . eval "storage_spec::${s}::get_error_msg;";
	}
	#################################################################
	# We need to run against each vg separately.			#
	#################################################################
	my $VGS=$res->[0]->{vgs};
	my @VGLIST=split(/,/,$VGS);
	my $VG;
	my @R=();
	my @info2;
	for $VG (@VGLIST) {
		my ($rc,$msg)=$STORAGE->onode_postmigrate($VG,$application,$new_node);
		if($rc==1) {
			return "ERROR USEABLE $msg";
		}
		if($rc==2) {
			return "ERROR NOT_USEABLE $msg";
		}
	}
	return "OK";
}

1;
